package com.dola.web.security;

import java.util.LinkedList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

import com.dola.service.IServiceUser;

@Component
public class CustomUserDetails implements UserDetailsService {

	@Autowired
	IServiceUser sUser;

	public UserDetails loadUserByUsername(String userName) {
		UserDetails userDetails = null;
		LinkedList<GrantedAuthority> roles = new LinkedList<>();
		com.dola.entity.User user = sUser.getByName(userName);
		if (user != null) {
			userDetails = new User(user.getUserName(), user.getPassWord(), roles);
		}
		return userDetails;
	}
}
